package com.labManage.util;

import com.labManage.vo.BorrowButtonWord;
import com.labManage.vo.BorrowHandleState;
import com.labManage.vo.GoodsHandleState;

public class BorrowStateUtil {
    private static BorrowStates[] borrowWordTable = new BorrowStates[]{
            new BorrowStates(BorrowHandleState.BORROW_APPLYING, BorrowButtonWord.AGREE_BORROW),
            new BorrowStates(BorrowHandleState.AGREED_BORROW_APPLY, BorrowButtonWord.AGREED_BORROW),
            new BorrowStates(BorrowHandleState.REBACK_APPLYING, BorrowButtonWord.AGREE_REBACK),
            new BorrowStates(BorrowHandleState.AGREED_REBACK_APPLY, BorrowButtonWord.AGREED_REBACK),
            new BorrowStates(BorrowHandleState.NOT_NEED_REBACK, BorrowButtonWord.AGREED_BORROW),
            new BorrowStates(BorrowHandleState.NUM_NOT_ENOUGH,BorrowButtonWord.REFUSE_BORROW)
    };

    public static String getBorrowHandleStateChanged(String nowBorrowHandleState,Boolean needReback){
        if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == true))){
            return BorrowHandleState.AGREED_BORROW_APPLY;
        }else if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == false))){
            return BorrowHandleState.NOT_NEED_REBACK;
        }else if(nowBorrowHandleState.trim().equals(BorrowHandleState.REBACK_APPLYING)){
            return BorrowHandleState.AGREED_REBACK_APPLY;
        }else {
            return null;
        }
    }

    public static String getGoodsHandleStateChanged(String nowBorrowHandleState,Boolean needReback){
        if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == true))){
            return GoodsHandleState.ALLOW_REBACK;
        }else if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == false))){
            return GoodsHandleState.ALLOW_BORROW;
        }else if(nowBorrowHandleState.trim().equals(BorrowHandleState.REBACK_APPLYING)){
            return GoodsHandleState.ALLOW_BORROW;
        }else{
            return null;
        }
    }

    public static String getGoodsStateChanged(String nowBorrowHandleState,Boolean needReback){
        if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == true))){
            return "不在库";
        }else if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == false))){
            return "在库";
        }else if(nowBorrowHandleState.trim().equals(BorrowHandleState.REBACK_APPLYING)){
            return "在库";
        }else{
            return null;
        }
    }

    public static String getGoodsState(String nowBorrowHandleState,Boolean needReback){
        if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == true))){
            return "不在库";
        }else if((nowBorrowHandleState.trim().equals(BorrowHandleState.BORROW_APPLYING)&&(needReback == false))){
            return "在库";
        }else if(nowBorrowHandleState.trim().equals(BorrowHandleState.REBACK_APPLYING)){
            return "在库 ";
        }else{
            return null;
        }
    }
    public static String getBorrowButtonWord(String BorrowHandleState){
        String word = "";
        for(int i=0;i<borrowWordTable.length;i++){
            if(BorrowHandleState.trim().equals(borrowWordTable[i].borrowHandleState)){
                return  borrowWordTable[i].borrowWord;
            }
        }
        return null;
    }

    public static Boolean getBorrowButtonEnable(String BorrowHandleStatete){
        if(BorrowHandleStatete.trim().equals(BorrowHandleState.BORROW_APPLYING)){
            return true;
        }else if(BorrowHandleStatete.trim().equals(BorrowHandleState.AGREED_BORROW_APPLY)){
            return false;
        }else if(BorrowHandleStatete.trim().equals(BorrowHandleState.REBACK_APPLYING)){
            return true;
        }else if(BorrowHandleStatete.trim().equals(BorrowHandleState.AGREED_REBACK_APPLY)){
            return false;
        }else if(BorrowHandleStatete.trim().equals(BorrowHandleState.NOT_NEED_REBACK)){
            return false;
        }else if(BorrowHandleStatete.trim().equals(BorrowHandleState.NUM_NOT_ENOUGH)){
            return false;
        }else{
            return false;
        }
    }
}

class BorrowStates{
    String borrowHandleState;
    String borrowWord;

    public BorrowStates(String borrowHandleState, String borrowWord) {
        this.borrowHandleState = borrowHandleState;
        this.borrowWord = borrowWord;
    }
}
